let fs = require('fs');
let path = require('path');
let resFormatRouter = require('./resFormatRouter');
// let logRouter = require('./logRouter');
let VerifyRouter = require('./verifyRouter');
let MulterTool = require('../lib/multerTool');
const WeChatPayCallBackRouter = require('./weChatPayCallBackRouter');
module.exports = function (app) {
    app.use('/', resFormatRouter.formatResponse);
    // app.use('/', resFormatRouter.formatResponse,logRouter.logRouter);
    app.use('/recharge', WeChatPayCallBackRouter.weChatPayRouter);
    // app.use('/pc',function (req,res,next) {
    //     console.log(req.session);
    //     if(req.path == "/account/login" || req.session.account){
    //         next();
    //     }else{
    //         return res.rej({code:302});
    //     }
    // });
    fs.readdirSync(__dirname + '/pc').forEach(function (fileName) {
        let modelName = fileName.split('.js')[0];
        app.use('/pc/' + modelName + '/', require(path.join(__dirname + '/pc/', fileName)));
    });
    app.use(MulterTool.upload.any());
    app.use('/', VerifyRouter.verifyToken);
    fs.readdirSync(__dirname + '/app').forEach(function (fileName) {
        let modelName = fileName.split('.js')[0];
        app.use('/app/' + modelName + '/', require(path.join(__dirname + '/app/', fileName)));
    });
    fs.readdirSync(__dirname + '/log').forEach(function (fileName) {
        let modelName = fileName.split('.js')[0];
        app.use('/log/' + modelName + '/', require(path.join(__dirname + '/log/', fileName)));
    });
};

